from transapp.Upper import Upper


class TransApp(object):

    def __init__(self, transList):
        self._transList = transList
        self._selectedTransList = []
        self._transMap = {}
        self._transMap["Upper"] = Upper()

    def setView(self, view):
        self._transView = view
        self._transView.initTransformer(self._transList)

    def addTrans(self, trans):
        self._selectedTransList.append(trans)
        self._transView.refreshSelectedTrans(self._selectedTransList)

    def removeTrans(self, trans):
        self._selectedTransList.remove(trans)
        self._transView.refreshSelectedTrans(self._selectedTransList)

    def removeAllTrans(self):
        self._selectedTransList = []
        self._transView.refreshSelectedTrans(self._selectedTransList)

    def applyTransform(self):
        oriString = self._transView.getOriString()
        result = oriString
        for a in self._selectedTransList:
            result = self._transMap[a].apply(result)
        self._transView.showResultString(result)

